package com.imooc.springcloud.hystrix;

import com.imooc.springcloud.Friend;
import com.imooc.springcloud.IService;
import com.imooc.springcloud.MyService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @desc
 * @author zkw
 * @date 2021-03-27
 */
@Component
@Slf4j
public class Fallback implements MyService {
    @Override
    public String sayHi() {
        return null;
    }

    @Override
    public Friend sayHiPost(Friend friend) {
        return null;
    }

    @Override
    public String retry(int timeout) {
        return "You are late !";
    }

    @Override
    @HystrixCommand(fallbackMethod = "fallback2")
    public String error() {
        log.info("fallback:error");
        throw new RuntimeException("fallback:error");
    }

    @HystrixCommand(fallbackMethod = "fallback3")
    public String fallback2() {
        log.info("fallback2");
        throw new RuntimeException("fallback2");
    }

    public String fallback3() {
        log.info("fallback3");
        return "success";
    }

}
